package com.tcoiss.kettle.server.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tcoiss.kettle.common.povo.Result;
import com.tcoiss.kettle.server.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述:
 *
 * @author leo
 * @create 2019-12-30 16:34
 */
@RestController
@RequestMapping("/system")
public class SystemController {

    @Autowired
    SystemService sysSystemService;

    @GetMapping("/getSystemList.do")
    public Result<PageInfo> getSystemList(int page, int rows) {
        PageHelper.startPage(page, rows);
        PageInfo<System> pageInfo = new PageInfo<>(sysSystemService.getSystemList());
        return Result.ok(pageInfo);
    }

    @PostMapping("/getSystemById.do")
    public Result<System> getSystemById(String id) {
        return Result.ok(sysSystemService.getSystemById(id));
    }

    @PostMapping("/addSystem.do")
    public Result addSystem(System system) {
        return Result.ok(sysSystemService.addSystem(system));
    }

    @PostMapping("/updateSystem.do")
    public Result updateSystem(System system) {
        return Result.ok(sysSystemService.updateSystem(system));
    }

    @PostMapping("/deleteSystem.do")
    public Result deleteSystem(String id) {
        sysSystemService.deleteSystem(id);
        return Result.ok();
    }

    @GetMapping("/searchSystem")
    public Result<PageInfo> searchSystem(int page, int rows, String keyword) {
        PageHelper.startPage(page, rows);
        PageInfo<System> pageInfo = new PageInfo<>(sysSystemService.searchSystem(keyword));
        return Result.ok(pageInfo);
    }

}
